package com.shanshan.crowd.controller;

import com.shanshan.crowd.api.MySQLRemoteService;
import com.shanshan.crowd.constant.CrowdConstant;
import com.shanshan.crowd.entity.vo.PortalTypeVO;
import com.shanshan.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Description
 * @ClassName PortalController
 * @Author 山山大魔王
 * @Date 2022/7/28 20:17
 * @Version 1.0
 */
@Controller
public class PortalController {

    @Autowired
    MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String showPortalPage(Model model){
//        需要加载数据

        // 1、
        ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeProjectDataRemote();

        // 2、
        String result = resultEntity.getOperationResult();

        if (ResultEntity.SUCCESS.equals(result)){
            // 3.
            List<PortalTypeVO> list = resultEntity.getQueryData();

            // 4.
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, list);
        }

        return "portal";
    }
}
